var myFunc = require("myCommonFunction.js");

threads.start(function () {
    opreate();
    exit();
});

threads.start(function () {
    sleep(180000)
    exit();
});

function opreate() {
    var ret = myFunc.initNetWork(null, true);
    if (ret) {
        jingdong();
    }
}

function jingdong() {
    myFunc.openMyApp("京东");
    var a = text("领券").findOne(5000);
    if (a == null) {
        myFunc.tuichu("京东");
        jingdong();
    } else {
        a.parent().click();
        sleep(1000);
        idContains("df").findOne(3000)
        var now = new Date();
        var min = now.getMinutes();
        var sec = now.getSeconds;
        var isClick = false;
        var waitTime = 100;
        if (0 < min && min < 2 && sec < 5) {
            waitTime = 3000;
            isClick = true;
        } else if (min > 58) {
            isClick = true;
            waitTime = (65 - sec) * 1000;
        }

        threads.start(function () {
            while (isClick) {
                click(1195, 2032);
                sleep(100);
            }
        });
        sleep(waitTime)
        isClick = false;

        myFunc.tuichu("京东");
    }
}

                                                                                            
                                                                                            
                                                                                            
                                                                                            
                                                                                            
                                                                                            
                                                                                            
                                                                     